package br.eck.model.base.misc;

import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

import br.eck.model.base.DestrucatableObject;
import br.eck.model.base.Effect;
import br.eck.model.base.effects.SpriteBasedEffect;

/**
 * Classe que cria um meteoro na tela
 * 
 * @author Erick Zanardo
 *
 */
public class Meteor extends DestrucatableObject{

    private SpriteSheet sheet;
    private int timeStep;
    private int actualImage;

    private static int INTERVAL = 500;

    public Meteor() throws SlickException {
        Effect e = new SpriteBasedEffect(new SpriteSheet("img/effects/explosion.png", 65, 81), 20);
        setOnDestroyEffect(e);
        sheet = new SpriteSheet("img/misc/meteor.png", 54, 54);
        timeStep = 0;
        actualImage = 0;
        setImage(sheet.getSprite(0, 0));

        setEnergy(50);
        setDef(15);
        setMass(100);
    }

    @Override
    public void update(int timePassed, Input input) {
        timeStep += timePassed;
        if (timeStep >= INTERVAL) {
            timeStep = timeStep - INTERVAL;
            if (actualImage < sheet.getHorizontalCount() - 1) {
                actualImage++;
            } else {
                actualImage = 0;
            }
            setImage(sheet.getSprite(actualImage, 0));
        }

        setY(getY() + ((timePassed / 1000f) * 90f));
        updateDestroySpriteBasedEffect();
    }
}
